<template>
	<view class="list-box mar-top-40 rowW gap30">
		<view class="list bg-white mar-bottom-24 radius24" v-for="(item,index) in list" :key="index"
			@click="hanldeSaleList(item.id)">
			<view class="goods-image">
				<image :src="item.goods_info.cover" mode="aspectFill"></image>

				<view class="status-box sale-status pad-left-right-32 pad-top-bottom-16 color-white font-24">
					<view v-if="item.sold_cnt >= item.stock">
						<view class="centerY">
							<image class="sale-icon" src="../../static/icon/sale-done.png"></image>
							<text class="mar-left-10">已售罄</text>
						</view>
					</view>

					<template v-else>
						<!-- 优先购时间 -->
						<template v-if="item.first_at > 0">
							<view class="centerXY" v-if="newTime < item.first_at">
								<text>优先购：</text>
								<u-count-down @finish="hanldeFinish" :time="countDown(item.first_at,newTime)"
									format="HH:mm:ss"></u-count-down>
							</view>
							<!-- 活动进行中 -->
							<view class="status centerXY font-24"
								v-if="newTime >= item.first_at && newTime < item.end_at">
								<text>火热进行中</text>
							</view>
							<!-- 活动也结束 -->
							<view class=" bg-hui centerXY font-24" v-if="item.end_at < newTime">
								<image class="sale-icon" src="../../static/icon/sale-done.png"></image>
								<text class="mar-left-5">活动已结束</text>
							</view>
						</template>

						<!-- 正常购 -->
						<template v-else>
							<!-- 活动未开始 -->
							<view class="centerY " v-if="newTime < item.begin_at">
								<text class="mar-right-5 font-24">开始后：</text>
								<u-count-down @finish="hanldeFinish" :time="countDown(item.begin_at,newTime)"
									format="HH:mm:ss"></u-count-down>
							</view>
							<!-- 活动进行中 -->
							<view class="status centerXY font-24"
								v-if="newTime >= item.begin_at &&  newTime < item.end_at">
								<text>火热进行中</text>
							</view>
							<!-- 活动也结束 -->
							<view class=" bg-hui centerXY font-24" v-if="item.end_at < newTime">
								<image class="sale-icon" src="../../static/icon/sale-done.png"></image>
								<text class="mar-left-5">活动已结束</text>
							</view>
						</template>
					</template>
				</view>

				<view class="goods-info centerY">
					<view class="flex-w">
						<view class="name color-white font-36">{{item.goods_info.name}}</view>
						<view class="centerY mar-top-20">
							<view class="title centerY">
								<image class="avatar" :src="item.goods_info.author_info.avatar" mode="aspectFill"></image>
								<text class="font-24 color-white mar-left-8">{{item.goods_info.author_info.name}}</text>
							</view>
							<capsule title="限量" :number="item.goods_info.build" unit="份" class="mar-left-20"></capsule>
						</view>
					</view>
					<view class="price color-white font-48 text-right"><text class="font-28">￥</text>{{item.price}}
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				newTime: parseInt(new Date().getTime() / 1000)
			}
		},
		methods: {
			// 倒计时计算 time - time1 *1000
			countDown(time, time1) {
				return (time - time1) * 1000;
			},
			// 切换状态
			hanldeFinish() {
				this.newTime = parseInt(new Date().getTime() / 1000);
			},
			// 跳转详情
			hanldeSaleList(id) {
				this.$emit('hanldeSaleList', id)
			}
		}
	}
</script>

<style scoped lang="scss">
	.title image {
		display: block;
		width: 32rpx;
		height: 32rpx;
		border-radius: 50%;
	}

	.list {
		width: 690rpx;
		border: 2rpx solid $uni-theme;
	}

	.goods-image {
		position: relative;

		image {
			display: block;
			width: 690rpx;
			height: 690rpx;
			border-radius: 24rpx;
		}

		.status-box {
			position: absolute;
			top: 30rpx;
			left: 30rpx;

			::v-deep .u-count-down__text {
				display: block;
				width: 110rpx;
				line-height: 34rpx;
				font-size: 24rpx;
				color: white;
			}
		}

		.sale-status {
			background: rgba(0, 0, 0, .5);
			border-radius: 30rpx;
		}

		.sale-icon {
			width: 32rpx;
			height: 32rpx;
		}

		.goods-info {
			position: absolute;
			bottom: 0rpx;
			width: 100%;
			background: rgba(0, 0, 0, .6);
			border-radius: 0 0 24rpx 24rpx;
			padding: 15rpx 45rpx 15rpx 34rpx;
			box-sizing: border-box;
		}
		
		.avatar{
			width: 32rpx;
			height: 32rpx;
		}

	}
</style>